(function () {
    angular.module('app')
        .component('xxShowAllQuestion', {
            templateUrl: '/app/consultant/showAllQuestion/showAllQuestion.html',
            controller: ctrl
        });

    function ctrl($scope,userService,ShowAllQuestionFactory,$state) {
        /**
         * purpose:http post
         */
        //$scope.isAdmin = userService.isAdmin;
        if (userService.username=='admin')$scope.isAdmin = true;
            $scope.allEssay = [];
        function getAllEssay() {
            function cb(err,res) {
                if(!err)$scope.allEssay = res;
                //console.log(res);
                //console.log(res['res'][0]['isAnswer']);
            }
            ShowAllQuestionFactory.getAllEssay(cb);
        }
        getAllEssay();

        $scope.types = ["所有问题","已回答","未回答"];
        $scope.selectedType = $scope.types[0];
        $scope.selectedQuestion = [];
        //$scope.isAnswer = res['res'][0]['isAnswer'];
        //console.log($scope.isAnswer);


        /*
        $scope.changeQuestion = function (type) {
            //console.log(type);
            switch($scope.selectedType){
                case '所有提问':
                    break;
                case '已回答':

                    break;
                case '未回答':

                    break;
            }
        }
        */

        $scope.getEssayById = function (essayId) {
            $state.go("show.get-essay-by-id",{essayId:essayId});
        }

        var reload = function () {
            $scope.allEssay = getAllEssay();
        };
        $scope.reload =function () {
            $scope.allEssay = [];
            reload();
        };
        $scope.deleteEssayById = function (essayId) {
            function cb(err,res) {
                if(!err)console.log(err,res);
            }
            ShowAllQuestionFactory.deleteEssayById(essayId,cb);
            reload();  //test
        }
    }

})()
